package me.zk.practice1.hw;

import java.util.*;

/**
 * @author zhangkai
 * @date 2023/8/11 17:39
 */
public class HWBJJ03 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] dies = scanner.nextLine().split(",");
        String[] strings = s.split(",");

        Set<String> dieSet = new HashSet<>();
        dieSet.addAll(Arrays.asList(dies));
        Set<String> set = new HashSet<>();
        for (int i = 0; i < strings.length; i++) {
            String[] ll = strings[i].split("-");
            String child = ll[0];
            String f = ll[1];

            if (dieSet.contains(f)) {
                //子节点死去
                dieSet.add(child);
                //如果假如了子节点，则去掉
                set.remove(child);
                set.remove(f);
            } else if (dieSet.contains(child)) {
                set.add(f);
            }else {
                set.add(f);
                set.add(child);
            }

        }
        for (String f: set) {
            System.out.println(f);
        }

    }
}
